package store.pages;

import org.openqa.selenium.By;
import org.rslai.autotest.core.page.AbstractPageObject;
import org.springframework.stereotype.Component;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;

/**
 * 页面：首页 <br>
 * 前台
 * 
 * @author rslai
 *
 */
@Component
public class Po_Home extends AbstractPageObject {

	@Override
	protected void switchToFrame() {
		
	}

	/**
	 * 打开前台首页
	 */
	@Given("^打开前台首页$")
	public void open_Page() {
		super.navigate.get_Page("");
	}

	/**
	 * “搜索” 输入框<br>
	 * Frame: 
	 * 
	 * @param keyword
	 */
	@When("^输入搜索内容 \"([^\"]*)\"$")
	public void input_keyword(String keyword) {
		if (super.wait.isDisplayedElement(By.xpath("//html"), "id('kw')")) {
			super.sendkeys.sendKeys(By.id("kw"), keyword);
		} else {
			super.sendkeys.sendKeys(By.id("kw1"), keyword);
		}
	}

	/**
	 * “百度一下” 按钮<br>
	 * Frame: 
	 */
	@When("^单击百度一下$")
	public void click_Search() {
		if (super.wait.isDisplayedElement(By.xpath("//html"), "id('su')")) {
			super.click.click(By.id("su"));
		} else {
			super.click.click(By.id("su1"));
		}
	}

	/**
	 * 验证浏览器title内容
	 * @param str
	 * @throws Throwable
	 * Frame: 
	 */
	@Then("^浏览器Title为 \"([^\"]*)\"$")
	public void 浏览器Title为(String str) {
		this.assertions.assertEquals(str, driver().getTitle());
	}

}
